package com.easymin.weixin.controller.web;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;

import com.easymin.weixin.entity.WxAccount;
import com.easymin.weixin.manager.WxAccountManager;


@Controller
@RequestMapping("/")
public class FileNameController {

  @Autowired
  private WxAccountManager wxAccountManager;
  
  
  @RequestMapping(value = "{fileName}", method = RequestMethod.GET)
  public @ResponseBody String index(@PathVariable("fileName") String fileName,HttpServletRequest request,
      HttpServletResponse response) {
    String[] strings = request.getServletPath().split("/");
    response.setContentType("text/plain; charset=UTF-8");
    if(strings!=null && strings.length>1){
      for (String string : strings) {
        if(StringUtils.isNotBlank(string)){
          WxAccount wxAccount = wxAccountManager.findByFileName(string);
            if(wxAccount!=null){
              return wxAccount.getFileContent();
            }
          }
      }
    }

    return "未能查询到数据！";
  }

 
}
